/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.deib.se2.meteocal.business.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.validation.constraints.NotNull;

@Entity(name = "CALENDARS")
public class Calendar implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Id
    @NotNull
    private Long id;
    
    @NotNull
    private boolean isPublic;
        
    @NotNull
    private boolean mailNotification;
    
    //interval of weather update
    //not yet implemented
    private int weatherNotification;
    
    //calendar has one user
    @OneToOne
    @JoinColumn(name = "owner_email", referencedColumnName = "email")
    private User owner_email;
    
    //calendar has many events
    @ManyToMany
    private Collection<Event> eventCollection;
    
    public Calendar(){
        eventCollection = new ArrayList<Event>();
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the isPublic
     */
    public boolean isIsPublic() {
        return isPublic;
    }

    /**
     * @param isPublic the isPublic to set
     */
    public void setIsPublic(boolean isPublic) {
        this.isPublic = isPublic;
    }

    /**
     * @return the owner
     * 
     * forse sarebbe meglio un costruttore che restituisce solo l'id?
     */
    public User getOwner() {
        return getOwner_email();
    }

    /**
     * @param owner the owner to set
     */
    public void setOwner(User owner) {
        this.setOwner_email(owner);
    }

    /**
     * @return the mailNotification
     */
    public boolean isMailNotification() {
        return mailNotification;
    }

    /**
     * @param mailNotification the mailNotification to set
     */
    public void setMailNotification(boolean mailNotification) {
        this.mailNotification = mailNotification;
    }

    /**
     * @return the weatherNotification
     */
    public int getWeatherNotification() {
        return weatherNotification;
    }

    /**
     * @param weatherNotification the weatherNotification to set
     */
    public void setWeatherNotification(int weatherNotification) {
        this.weatherNotification = weatherNotification;
    }    

    /**
     * @return the event collection
     */
    /*
    public Collection<Event> getEvents() {
        return getEventCollection();
    }
*/
    /**
     * @param eventCollection the event collection to set
     */
    /*
    public void setEvents(Collection<Event> eventCollection) {
        this.setEventCollection(eventCollection);
    }
    public void setEvent(Event event){
        this.getEventCollection().add(event);
    }
*/
    /**
     * @return the owner_email
     */
    public User getOwner_email() {
        return owner_email;
    }

    /**
     * @param owner_email the owner_email to set
     */
    public void setOwner_email(User owner_email) {
        this.owner_email = owner_email;
    }

    /**
     * @return the eventCollection
     */
    public Collection<Event> getEventCollection() {
        return eventCollection;
    }

    /**
     * @param eventCollection the eventCollection to set
     */
    public void setEventCollection(Collection<Event> eventCollection) {
        this.eventCollection = eventCollection;
    }
    
    public void setEvent(Event event){
        this. eventCollection.add(event);
    }
    
}
